package com.itWaiLong.Service.Impl;


import com.itWaiLong.Dao.personal_info;
import com.itWaiLong.Mapper.ImproveMapper;
import com.itWaiLong.Service.ImproveService;
import com.itWaiLong.Utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class ImproveServiceImpl implements ImproveService {

    @Autowired
    private ImproveMapper improveMapper;

    @Override
    public int ImproveUserInfo(personal_info personal_info) {

        //获取用户id
        Map<String, Object> map = ThreadLocalUtil.getThreadLocal();
        int userId = (int) map.get("userId");

        //通过用户id查看用户是否已经完善个人信息
        personal_info personalInfo = improveMapper.viweImproveInfoByUserId(userId);
        if (personalInfo != null) {
            return -1;//用户已经完善过信息了
        }
        //设置用户id（外键id）
        personalInfo.setUserId(userId);
        return improveMapper.ImproveUserInfo(personalInfo);
    }

    @Override
    public int updateImproveInfo(personal_info personalInfo) {

        //获取用户id
        Map<String, Object> map = ThreadLocalUtil.getThreadLocal();
        int userId = (int) map.get("userId");
        personalInfo.setUserId(userId);

        return improveMapper.updateImproveInfo(personalInfo);
    }
}
